MOVES = [
    (2, 1), (1, 2), (-1, 2), (-2, 1),
    (-2, -1), (-1, -2), (1, -2), (2, -1)
]

def find_knight_paths(m, n, start_pos, target_pos):
    board = [[0 for _ in range(n)] for _ in range(m)]
    successful_paths = []
    
    def backtrack(x, y, path):
        if (x, y) == target_pos:
            successful_paths.append(path.copy())
            return
        
        for dx, dy in MOVES:
            next_x, next_y = x + dx, y + dy
            if 0 <= next_x < m and 0 <= next_y < n and board[next_x][next_y] == 0:
                board[next_x][next_y] = 1
                path.append((next_x, next_y))
                
                backtrack(next_x, next_y, path)
                
                board[next_x][next_y] = 0
                path.pop()
    
    start_x, start_y = start_pos
    board[start_x][start_y] = 1
    backtrack(start_x, start_y, [start_pos])
    
    print(f"Total successful paths: {len(successful_paths)}")
    for i, path in enumerate(successful_paths, 1):
        print(f"Path {i}: {' -> '.join(f'({x},{y})' for x, y in path)}")

# 示例使用
m, n = 5, 5  # 棋盘大小
start_pos = (0, 0)  # 起始位置
target_pos = (4, 4)  # 目标位置

find_knight_paths(m, n, start_pos, target_pos)